// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: braces fieldsfirst space lnc 
// Source File Name:   MenuActivity.java

package es.caeboxapps.game;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.android.Facebook;
import com.facebook.model.GraphUser;
import com.facebook.widget.ProfilePictureView;

import es.caeboxapps.game.utils.Utils;

public class MenuActivity extends Activity {

	Facebook facebook;
	SharedPreferences mPrefs;
	ProfilePictureView profilePictureView;
	Button shareButton;

	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.menu_activity);

		CheckBox checkBoxSonido = (CheckBox) findViewById(R.id.checkBoxSonido);
		Button btnIniciarJuego = (Button) findViewById(R.id.buttonIniciarJuego);
		checkBoxSonido.setChecked(true);
		checkBoxSonido
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						if (isChecked) {
							GameApplication.sonidoActivo = true;
						} else {
							GameApplication.sonidoActivo = false;
						}

					}
				});

		// Set Type Face
		Typeface font = Typeface.createFromAsset(getAssets(),
				"Bunaken_Underwater.ttf");
		btnIniciarJuego.setTypeface(font);
		checkBoxSonido.setTypeface(font);


		shareButton = (Button) findViewById(R.id.shareButton);
		shareButton.setOnClickListener(new View.OnClickListener() {
		    @Override
		    public void onClick(View v) {
		        Utils.publishStory(MenuActivity.this, null, null, null, null, null);        
		    }
		});
		profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);

		// start Facebook Login
		Session.openActiveSession(this, true, new Session.StatusCallback() {

			// callback when session changes state
			@Override
			public void call(Session session, SessionState state,
					Exception exception) {
				if (session.isOpened()) {
					shareButton.setVisibility(View.VISIBLE);
					profilePictureView.setVisibility(View.VISIBLE);
					//Comprueba si se estan obteniendo los permisos de publicacion
//					if (pendingPublishReauthorization && 
//					        state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
//					    pendingPublishReauthorization = false;
//					    publishStory();
//					}
					Request.newMeRequest(session,
							new Request.GraphUserCallback() {

								// callback after Graph API response with user
								// object
								@Override
								public void onCompleted(GraphUser user,
										Response response) {
									if (user != null) {
										TextView welcome = (TextView) findViewById(R.id.welcome);
										welcome.setText("Logeado en Facebook con "
												+ user.getName() + "!");
										// obtiene la imagen de perfil del usuario y la coloca
										profilePictureView.setProfileId(user.getId());
									}
								}
							}).executeAsync();

				} else if (session.isClosed()) {
					shareButton.setVisibility(View.INVISIBLE);
				}
			}
		});
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Session.getActiveSession().onActivityResult(MenuActivity.this,
				requestCode, resultCode, data);
	}	

	// ---------------------------------------------------------------------------
	// INICIAR JUEGO
	// -----------------------------------------------------------------------
	public void iniciarJuego(View view) {
		Intent intent = new Intent(this, QuestionActivity.class);
		startActivity(intent);
		GameApplication.listaPreguntas = Utils.getQuestions(this);
		finish();
	}

	protected void onResume() {
		super.onResume();

		// Reseteamos valores
		// ------------------
		GameApplication.posicionPreguntaActual = 0;
		GameApplication.numeroSaltos = GameApplication.NUMERO_DE_SALTOS;
		GameApplication.lifes = GameApplication.NUMERO_DE_VIDAS;
		GameApplication.nivelPartida = 1;
	}
}
